local guanhuo = fk.CreateSkill {
  name = "guanhuo",
}

guanhuo:addEffect("active", {
  anim_type = "offensive",
  card_num = 0,
  target_num = 1,
  prompt = "#guanhuo",
  can_use = function(self, player)
    return not player:prohibitUse(Fk:cloneCard("fire_attack"))
  end,
  card_filter = Util.FalseFunc,
  target_filter =function (self, player, to_select, selected, selected_cards, card, extra_data)
    local target = to_select
    return #selected == 0 and not target:isKongcheng() and not player:isProhibited(target, Fk:cloneCard("fire_attack"))
  end,
  on_use =function (self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    room:useVirtualCard("fire_attack", nil, player, target, self.name)
  end,
})


guanhuo:addEffect(fk.PreCardUse, {
  can_refresh = function(self, event, target, player, data)
    if target == player then
      return player:getMark("@@guanhuo-phase") > 0 and data.card.name == "fire_attack"
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    data.additionalDamage = (data.additionalDamage or 0) + 1
  end,
})

guanhuo:addEffect(fk.Damage, {
  can_refresh = function(self, event, target, player, data)
    if target == player then
      return data.card and table.contains(data.card.skillNames, "guanhuo")
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    data.card.extra_data = data.card.extra_data or {}
    table.insert(data.card.extra_data, "guanhuo")
  end,
})

guanhuo:addEffect(fk.CardUseFinished, {
  can_refresh = function(self, event, target, player, data)
    if target == player then
      return data.card and table.contains(data.card.skillNames, "guanhuo")
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if data.card.extra_data and table.contains(data.card.extra_data, "guanhuo") then return end
      if player:usedSkillTimes("guanhuo", Player.HistoryPhase) == 1 then
        room:addPlayerMark(player, "@@guanhuo-phase", 1)
      else
        room:handleAddLoseSkills(player, "-guanhuo", nil, true, false)
      end
  end,
})

return guanhuo